package com.jiyun.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.feign.UserFeign;
import com.jiyun.model.Consumer;
import com.jiyun.model.User;
import com.jiyun.service.ConsumerService;
import com.jiyun.vo.ResultResopnse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserFeign userFeign;

    @Autowired
    private ConsumerService consumerService;


    @RequestMapping("login")
    public ResultResopnse login(@RequestBody User user){
        LambdaQueryWrapper<Consumer> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Consumer::getUsername,user.getUsername());
        ResultResopnse logined = consumerService.login(user);
        try {
            if (logined.getCode().equals("1")){
                return userFeign.login(user);
            }else {
                return logined;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
